package Review;

import java.util.Scanner;

public class Dfs2 {
    static int n = 0;
    static int[] path = new int[10];
    static boolean[] st = new boolean[10];
    public static void dfs(int u){
        if(u == n){
            for (int i = 0;i<n;i++){
                System.out.print(path[i] +" ");
            }
            System.out.println();
        }
        for (int i = 1;i<=n;i++){
            if(!st[i]){
                path[u] = i;
                st[i] = true;
                dfs(u+1);
                st[i] = false;
            }
        }
    }


        public static void main(String[] args){
            Scanner scanner = new Scanner(System.in);
            Scanner sc = new Scanner(System.in);
            n = sc.nextInt();
            dfs(0);


    }
}
